package com.heima.mapper;

import com.heima.pojo.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface NodeMapper {
    @Select("select id,name from tb_business ")
    List<Business> selectBusinessList();
    @Select("select name from tb_node where name = #{name}")
    String selectNodeName(String name);

    void insertNode(Node node);
    @Select("select * from tb_vending_machine where node_id = #{nodeId}")
    List<VendingMachine> selectVendingMachine(String nodeId);
    @Select("select * from tb_node where id = #{nodeId}")
    Node selectNodeByNodeID(String nodeId);
    @Select("select * from tb_region where id = #{regionId}")
    Region selectRegionByRegionId(Long regionId);
    @Select("select * from tb_business where id = #{businessId}")
    Business selectBusinessById(Integer businessId);
    @Select("select * from tb_vm_type where type_id = #{vmType};")
    Type selectVMTypeByvmType(Integer vmType);
    @Update("update tb_node set name = #{name} ,area_code = #{areaCode},addr = #{addr}, " +
            "create_user_id = #{createUserId} ,region_id =#{regionId} ,business_id = #{businessId} ,owner_id = #{ownerId},\n" +
            "owner_name =#{ownerName} ,update_time =#{updateTime}  where id = #{id}; ")
    void updateNode(Node node);
    @Select("select count(*) from tb_order o left join tb_order_collect oc on o.node_id = oc.node_id where  o.node_id = #{nodeId} or oc.node_id =#{nodeId}")
    int selectTborderAndCollect(int nodeId);
    @Delete("delete from tb_node where id = #{nodeId}")
    void deleteNode(int nodeId);
}
